﻿using MonitorPrism_Practice.Model;
using SCADALight.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MonitorPrism_Practice.ViewModels
{
    public class InterfaceLoggerViewModel : BindableBase
    {
        private IEventAggregator _aggregator { get; }

        public InterfaceLoggerViewModel()
        {
            _aggregator = ContainerLocator.Current.Resolve<IEventAggregator>();
            _aggregator.GetEvent<LogEvent>().Subscribe(AddLog);
        }
        private ObservableCollection<LogEventModel> _loggerCollection = new ObservableCollection<LogEventModel>()
        {
          
        };
        public ObservableCollection<LogEventModel> LoggerCollection
        {
            get { return _loggerCollection; }
            set
            {
                SetProperty(ref _loggerCollection, value);
            }
        }


        private void AddLog(LogEventModel item)
        {
           
            Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
            {
                LoggerCollection.Add(item);
            }));
        }
    }
}
